/**
 * 
 */
package com.zhiteng.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhiteng.entity.SysDict;
import com.zhiteng.service.SysDictService;
import com.zhiteng.utils.common.ZTResult;

/**  
* <p>Title: SysSettingController.java</p>  
* <p>Description:系统设置Controller </p>  
* @author dragon  
* @date 2018年12月10日  
* @version 1.0  
*/
@Controller
@RequestMapping("/sysSetting")
public class SysSettingController {
	@Autowired
	private SysDictService sysDictSerivce;
	
	/**
	 * 
	* @Title: saveReason  
	* @Description: 添加请假/调课/代课原因  
	* @param schoolId 学校id
	* @param label 原因
	* @param type 类型：如请假的type=leave,调课的type=adjust
	* @return ZTResult<Object>   
	* @throws
	 */
	@RequestMapping("/saveReason")
	@ResponseBody
	public ZTResult<Object> saveReason(SysDict dict){
		if(StringUtils.isAnyBlank(dict.getSchoolId(),dict.getLabel(),dict.getType())) {
			return ZTResult.result(1,"添加失败，请检查是否有参数为空");
		}
		int result = sysDictSerivce.saveDict(dict);
		if(result==1) {
			return ZTResult.result(0,"添加成功");
		}else {
			return ZTResult.result(1,"添加失败");
		}
		
	}
	
	/**
	 * 
	* @Title: deleteReason  
	* @Description: 删除请假/调课/代课原因    
	* @param id	数据字典id
	* @param schoolId	学校id
	* @return ZTResult<Object>   
	* @throws
	 */
	@RequestMapping("/deleteReason")
	@ResponseBody
	public ZTResult<Object> deleteReason(SysDict dict){
		if(StringUtils.isAnyBlank(dict.getSchoolId(),dict.getId())) {
			return ZTResult.result(1,"添加失败，请检查是否有参数为空");
		}
		int result = sysDictSerivce.deleteDictById(dict);
		if(result==1) {
			return ZTResult.result(0,"删除成功");
		}
		return ZTResult.result(1,"删除失败");
	}
	
	/**
	 * 
	* @Title: queryReasons  
	* @Description: 查询请假/调课/代课原因   
	* @param schoolId	学校id
	* @return ZTResult<Object>   
	* @throws
	 */
	@RequestMapping("/queryReasons")
	@ResponseBody
	public ZTResult<Object> queryReasons(@RequestParam(name="schoolId")String schoolId){
		if(StringUtils.isAnyBlank(schoolId)) {
			return ZTResult.result(1,"添加失败，请检查是否有参数为空");
		}
		List<SysDict> dictList = sysDictSerivce.queryDictBySchoolId(schoolId);
		return ZTResult.result(0, "查询成功",dictList);
	}
	
}
